module.exports = {

    /**@param {Creep}creep */
    run: function (creep) {

        var targets = creep.room.find(FIND_MY_CREEPS, {
            filter: (target) => target.hits < target.hitsMax
        });
        if (targets.length > 0) {
            creep.say('hh');
            if (creep.heal(targets[0]) == ERR_NOT_IN_RANGE) {
                creep.moveTo(targets[0], { visualizePathStyle: { stroke: 'rgb(9, 160, 55)' } });
            }
        }
        else {
            if (creep.memory.repair) {
                creep.say('r');
                targets = creep.room.find(FIND_STRUCTURES, {
                    filter: (structure) => structure.hits < structure.hitsMax
                });
                if (targets.length > 0 && creep.repair(targets[0]) == ERR_NOT_IN_RANGE) {
                    creep.moveTo(targets[0], { visualizePathStyle: { stroke: 'rgb(9, 160, 55)' } });
                }
                if (creep.store[RESOURCE_ENERGY] < 1) {
                    creep.memory.repair = false;
                }
            }
            else {
                var sources = creep.room.find(FIND_SOURCES_ACTIVE);
                if (creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
                    creep.moveTo(sources[0], { visualizePathStyle: { stroke: 'rgb(9, 160, 55)' } });
                }
                if (creep.store.getFreeCapacity() < 1) {
                    creep.memory.repair = true;
                }
            }
        }

    }
}